package com.core.common.domain.response;

import com.core.common.cons.RespCode;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: honglei
 * @time: 2021/3/4 0004 10:54
 */
@Data
public class R {
	private int status=200;
	private int code=200;
	private String msg="ok";
	private Object data;

	public void  sssetStatus(int code){
		this.status=code;
		this.code=code;
	}


	public static R error(RespCode respCode){
		R result=new R();
		result.setStatus(respCode.getCode());
		result.setMsg(respCode.getMsg());
		result.setData(null);
		return result;
	}

	public static R ok(){
		return new R();
	}

	public static R ok(Object data){
		R result=new R();
		result.setData(data);
		return result;
	}

//
//	public static R error(RegCodeEnum regCodeEnum){
//		R result=new R();
//		result.setCode(regCodeEnum.getCode());
//		result.setMsg(regCodeEnum.getDesc());
//		result.setData(null);
//		return result;
//	}

	public static R error(int code, String msg){
		R result=new R();
		result.setStatus(code);
		result.setMsg(msg);
		result.setData(null);
		return result;
	}

	public static R error( String msg){
		R result=new R();
		result.setStatus(40014);
		result.setMsg(msg);
		result.setData(null);
		return result;
	}
	public static R error(){
		R result=new R();
		result.setStatus(40014);
		result.setMsg("参数异常");
		result.setData(null);
		return result;
	}


	/*哎！为了兼容之前方法减少改动代码*/
	public R put(String key,Object value){
		Map map=new HashMap<>();
		map.put(key,value);
		R result=new R();
		result.setData(map);
		return result;
	}




}
